@extends('admin.layouts.main')
@section('header')
    @parent
    <style>
        .sp-input{
            width: 60px;
            float: left;
            margin-right: 20px;
        }
        .sp-input2{
            width: 70px;
        }
    </style>
@endsection
@section('content')
    <form class="layui-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">昵称</label>
                <div class="layui-input-inline">
                    <select name="user_id" id="userId" lay-search lay-verify="required">
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">序号</label>
                <div class="layui-input-inline">
                    <input class="layui-input" type="search" name="number" placeholder="序号" lay-verify="required" />
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">让球数</label>
                <div class="layui-input-inline">
                    <input class="layui-input" type="number" name="balls" placeholder="让球" value="-1" lay-verify="required" />
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">主队</label>
                <div class="layui-input-inline">
                    <input class="layui-input" type="search" name="host" placeholder="主队" lay-verify="required" />
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">客队</label>
                <div class="layui-input-inline">
                    <input class="layui-input" type="search" name="guest" placeholder="客队"  lay-verify="required"/>
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">截止时间</label>
                <div class="layui-input-inline">
                    <input class="layui-input" type="text" name="die_time" placeholder="截止时间" id="dieTime" lay-verify="required"/>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">赔率</label>
            <div class="layui-input-block">
                <input class="layui-input sp-input" type="text" name="sp11" placeholder=""  lay-verify="required"/>
                <input class="layui-input sp-input" type="text" name="sp12" placeholder=""  lay-verify="required"/>
                <input class="layui-input sp-input" type="text" name="sp13" placeholder=""  lay-verify="required"/>
                <input class="layui-input sp-input sp-input2" type="text" name="sp21" placeholder=""  lay-verify="required"/>
                <input class="layui-input sp-input sp-input2" type="text" name="sp22" placeholder=""  lay-verify="required"/>
                <input class="layui-input sp-input sp-input2" type="text" name="sp23" placeholder=""  lay-verify="required"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <input class="layui-input sp-ck" type="checkbox" name="result[]" value="1" title="胜">
                <input class="layui-input sp-ck" type="checkbox" name="result[]" value="2" title="平">
                <input class="layui-input sp-ck" type="checkbox" name="result[]" value="3" title="负">
                <input class="layui-input sp-ck" type="checkbox" name="result[]" value="4" title="让胜">
                <input class="layui-input sp-ck" type="checkbox" name="result[]" value="5" title="让平">
                <input class="layui-input sp-ck" type="checkbox" name="result[]" value="6" title="让负">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="match_id" value="">
                <input type="hidden" name="id" value="">
                <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="submit">立即提交</button>
            </div>
        </div>
    </form>
@endsection
@section('footer')
    @parent
    <script type="text/javascript">
       layui.use(['layer','jquery','form'],function () {
           var layer = layui.layer,
               $ = layui.jquery,
               form = layui.form;
           form.on("submit(submit)",function (data) {
               var formData = data.field;
                goConfirm('{{ url('admin/lottery/record/edit') }}',formData,'确认提交数据',1);
               return false;
           });

           getInfo();
           function getInfo() {
               var id = getUrlParam('id');
               $.get('{{ url('admin/lottery/record/detail') }}',{id:id},function (res) {
                   if(res.status == 200){
                       var data = res.data;
                       $('input[name="match_id"]').val(data.match_id);
                       $('input[name="id"]').val(data.id);
                       $('input[name="number"]').val(data.match.number);
                       $('input[name="balls"]').val(data.match.balls);
                       $('input[name="host"]').val(data.match.host);
                       $('input[name="guest"]').val(data.match.guest);
                       $('input[name="die_time"]').val(data.match.die_time);
                       $('input.sp-input:eq(0)').val(data['sp1'][0]);
                       $('input.sp-input:eq(1)').val(data['sp1'][1]);
                       $('input.sp-input:eq(2)').val(data['sp1'][2]);
                       $('input.sp-input:eq(3)').val(data['sp2'][0]);
                       $('input.sp-input:eq(4)').val(data['sp2'][1]);
                       $('input.sp-input:eq(5)').val(data['sp2'][2]);
                       if(data.result){
                           $.each(data.result,function (i,e) {
                               $('input.sp-ck[value="'+e+'"]').attr('checked',true);
                           })
                       }
                       buildOptions('{{ url('admin/user/selectList') }}',{},'#userId','id','nickname',data.user_id,true);
                   }
               },'json')
           }

           $("body").on('change','input[name="number"]',function () {
               var number = $(this).val();
               getMatch(number);
           });

           function getMatch(number) {
               $.get('{{ url('admin/lottery/match') }}',{number:number},function (res) {
                   if(res.status == 200){
                       var data = res.data;
                       $('input[name="match_id"]').val(data.id);
                       $('input[name="balls"]').val(data.balls);
                       $('input[name="host"]').val(data.host);
                       $('input[name="guest"]').val(data.guest);
                       $('input[name="die_time"]').val(data.die_time);
                       $('input.sp-input:eq(0)').val(data['sp1'][0]);
                       $('input.sp-input:eq(1)').val(data['sp1'][1]);
                       $('input.sp-input:eq(2)').val(data['sp1'][2]);
                       $('input.sp-input:eq(3)').val(data['sp2'][0]);
                       $('input.sp-input:eq(4)').val(data['sp2'][1]);
                       $('input.sp-input:eq(5)').val(data['sp2'][2]);
                   }
               },'json')
           }
       });

    </script>
@endsection